package com.yida.gwj.deposit.controller;

import com.yida.common.core.text.Convert;
import com.yida.common.core.utils.StringUtils;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.gwj.common.utils.GwjConvertUtil;
import com.yida.gwj.deposit.domain.GwjDepositBusinessHouse;
import com.yida.gwj.deposit.domain.dto.GwjDepositBusinessOwnerDTO;
import com.yida.gwj.deposit.domain.dto.split.GwjFundsSplitBusinessHouseDTO;
import com.yida.gwj.deposit.domain.request.GwjDepositBusinessOwnerRequest;
import com.yida.gwj.deposit.domain.request.split.GwjFundsSplitBusinessHouseRequest;
import com.yida.gwj.deposit.service.IGwjDepositBusinessHouseService;
import com.yida.gwj.deposit.service.IGwjDepositBusinessOwnerService;
import com.yida.gwj.deposit.service.IGwjDepositBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lqq
 * @date 2022-11-15
 */
@RestController
@RequestMapping("/business")
@Api(tags = "业主缴存管理模块（通用查询）")
public class GwjDepositBusinessController extends BaseController {

	@Autowired
	private IGwjDepositBusinessHouseService gwjDepositBusinessHouseService;

	@Autowired
	private IGwjDepositBusinessOwnerService gwjDepositBusinessOwnerService;

	@Autowired
	private IGwjDepositBusinessService gwjDepositBusinessService;

	@ApiOperation("房屋图标显示 楼栋下所有房屋")
	@GetMapping("/allHouse/{bizId}/{buildCode}")
	public AjaxResult allHouse(@PathVariable Long bizId, @PathVariable String buildCode) {
		GwjDepositBusinessHouse gwjDepositBusinessHouse = new GwjDepositBusinessHouse();
		gwjDepositBusinessHouse.setBizId(bizId);
		gwjDepositBusinessHouse.setBuildCode(buildCode);
		List<GwjDepositBusinessHouse> list = gwjDepositBusinessHouseService.selectGwjDepositBusinessHouseList(gwjDepositBusinessHouse);
		if (StringUtils.isEmpty(list)) {
			return AjaxResult.success(new ArrayList<>());
		}
		return AjaxResult.success(GwjConvertUtil.convertList(list, GwjFundsSplitBusinessHouseDTO.class));
	}

	@ApiOperation("业主信息")
	@GetMapping("/ownerInfo")
	public AjaxResult ownerInfo(@Validated GwjDepositBusinessOwnerRequest request) {
		return AjaxResult.success(GwjConvertUtil.convert(gwjDepositBusinessOwnerService.selectGwjDepositBusinessOwner(request.getHouseCode(), request.getBizId()), GwjDepositBusinessOwnerDTO.class));
	}

	@ApiOperation("房屋信息 不含楼栋名称、业主名称")
	@GetMapping("/houseList")
	public TableDataInfo houseList(@Validated GwjDepositBusinessHouse gwjDepositBusinessHouse) {
		startPage();
		List<GwjDepositBusinessHouse> list = gwjDepositBusinessHouseService.selectGwjDepositBusinessHouseList(gwjDepositBusinessHouse);
		return GwjConvertUtil.convertTable(getDataTable(list), GwjFundsSplitBusinessHouseDTO.class);
	}

	@ApiOperation("房屋详情列表 含楼栋信名称、业主名称")
	@PostMapping("/houseDetailList")
	public TableDataInfo houseDetailList(@RequestBody GwjFundsSplitBusinessHouseRequest request) {
		if (StringUtils.isNotBlank(request.getBuildCodeStr())) {
			request.setBuildCodes(Convert.toStrArray(request.getBuildCodeStr()));
		}
		startPage();
		return getDataTable(gwjDepositBusinessHouseService.selectGwjDepositBusinessHouseDetailList(request));
	}

	@ApiOperation("房屋详情列表 含楼栋信名称")
	@PostMapping("/houseBuildList")
	public TableDataInfo houseBuildList(@RequestBody GwjFundsSplitBusinessHouseRequest request) {
		if (StringUtils.isNotBlank(request.getBuildCodeStr())) {
			request.setBuildCodes(Convert.toStrArray(request.getBuildCodeStr()));
		}
		startPage();
		return getDataTable(gwjDepositBusinessHouseService.selectGwjDepositBusinessHouseWithBuildNameList(request));
	}

	@ApiOperation("房屋详情列表 含业主名称")
	@PostMapping("/houseOwnerList")
	public TableDataInfo houseOwnerList(@RequestBody GwjFundsSplitBusinessHouseRequest request) {
		if (StringUtils.isNotBlank(request.getBuildCodeStr())) {
			request.setBuildCodes(Convert.toStrArray(request.getBuildCodeStr()));
		}
		startPage();
		return getDataTable(gwjDepositBusinessHouseService.selectGwjDepositBusinessHouseWithOwnerNameList(request));
	}

	/**
	 * 查询对账方式
	 *
	 * @return
	 */
	@GetMapping("/getCheckAccountType")
	@ApiOperation("查询对账方式")
	public AjaxResult getCheckAccountType() {
		return AjaxResult.success(gwjDepositBusinessService.getCheckAccountType());
	}

	/**
	 * 查询对账状态
	 *
	 * @return
	 */
	@GetMapping("/getCheckAccountStatus")
	@ApiOperation("查询对账状态")
	public AjaxResult getCheckAccountStatus() {
		return AjaxResult.success(gwjDepositBusinessService.getCheckAccountStatus());
	}
}
